const express = require('express')
const bodyParser = require('body-parser')

//引入api接口
const user = require('./router/api/user')
const news = require('./router/api/news')
const topic = require('./router/api/topic')
const comment=require('./router/api/comment')

const app = express()

//使用bodyParser
app.use(bodyParser.urlencoded({
  extended: false
}))
app.use(bodyParser.json())

//跨域处理
let allowCrossDomain = function (req, res, next) {
  //请求源  ajax  http://localhost:8080
  res.header('Access-Control-Allow-Origin', '*')
  //请求头  x-token
  res.header('Access-Control-Allow-Headers', '*')
  //请求方法  get post put delete
  res.header('Access-Control-Allow-Methods', '*')
  next()
}
app.use(allowCrossDomain)


app.use('/api/user', user)
app.use('/api/news', news)
app.use('/api/topic', topic)
app.use('/api/comment',comment)


app.listen(3000, () => {
  console.log('启动成功')
})